<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>欢迎来到聊天室</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script type="application/javascript" src="/js/jquery-3.5.1.min.js"></script>
    <script type="application/javascript" src="/js/jquery.cookie.js"></script>
    <script type="application/javascript" src="/layui/layui.js"></script>
    <script type="application/javascript" src="/js/plugin.js"></script>
</head>

<body class="layui-layout-body">
    <!-- 内容主体区域 -->
    <form class="layui-form">
        <div class="layui-form-item" style="text-align: center;">
            <div class="layui-input-block">
                <input type="text" name="user_account" required lay-verify="required" placeholder="请输入账号" autocomplete="off"
                    class="layui-input" style="display: inline-block;width: auto;">
                <button class="layui-btn" lay-submit lay-filter="add">添加</button>
            </div>
        </div>
    </form>
    <script>
        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(add)', function (data) {
                $.ajax({
                    type: "post",
                    url: "/contacts/add",
                    dataType: "html",
                    contentType:"application/json",
                    data: JSON.stringify(data.field),
                    success: function () {
                        reload();
                    }
                });
                return false;
            });
        });
    </script>
</body>